package com.yxc.elasticsearchdemo.entiey;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yxc.elasticsearchdemo.config.CustomMappingEsConverter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.FieldNameConstants;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;

/**
 * @author: 杨旭晨
 * @time: 2022/6/22 16:49
 **/

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
//@Document(indexName = "demo")
@Document(indexName = "new-client-test1")
public class EsDemoEntity {

    @JsonIgnore
    @FieldNameConstants.Exclude
    private String _class;

    @Field(type = FieldType.Text, store = true)
    private String cId;

    @Field(type = FieldType.Text, store = true)
    private String cName;

    @Field(type = FieldType.Long, store = true)
    private Long cTime;

    @Field(type = FieldType.Text, store = true)
    private String cValue;

    public EsDemoEntity(String cId, String cName, Long cTime, String cValue) {
        this.cId = cId;
        this.cName = cName;
        this.cTime = cTime;
        this.cValue = cValue;
    }

    public static void main(String[] args) {
        MappingElasticsearchConverter mappingElasticsearchConverter = new CustomMappingEsConverter(
                new SimpleElasticsearchMappingContext());
        mappingElasticsearchConverter.afterPropertiesSet();
        MappingBuilder mappingBuilder = new MappingBuilder(mappingElasticsearchConverter);
        String s = mappingBuilder.buildPropertyMapping(EsDemoEntity.class);
        System.out.println(s);
    }
}
